package com.cipe.cmrs.model.ref;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

@MappedSuperclass
public abstract class BaseRef implements Serializable, Comparable<BaseRef> {

	
	private static final long serialVersionUID = 1981611416026470300L;

	@Id
	@GenericGenerator(name="system-assigned", strategy="assigned")
	@Column(name="id")
	@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
	protected Integer id;

	@Column(name="displayname")	
	protected String name;
	
	@Column(name="displayorder")	
	protected Integer displayOrder;

	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getDisplayOrder() {
		return displayOrder;
	}

	public void setDisplayOrder(Integer displayOrder) {
		this.displayOrder = displayOrder;
	}

	/**
	 * @see java.lang.Comparable#compareTo(Object)
	 */
	public int compareTo(BaseRef object) {
		if(object == null){
			return 1;
		} 
		
		return new CompareToBuilder()
				.append(this.displayOrder, object.displayOrder)
				.append(this.name, object.name)
				.toComparison();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	
	public int hashCode() {
		return new HashCodeBuilder()
				.appendSuper(super.hashCode()).append(this.id)
				.append(this.name).append(this.displayOrder)
				.toHashCode();
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	
	public boolean equals(Object object) {
		if (!(object instanceof BaseRef)) {
			return false;
		}
		BaseRef rhs = (BaseRef) object;
		return new EqualsBuilder().appendSuper(super.equals(object))
				.append(this.id, rhs.id)
				.append(this.name, rhs.name)
				.append(this.displayOrder, rhs.displayOrder)
				.isEquals();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	
	public String toString() {
		return new ToStringBuilder(this).append("id", this.id)
				.append("name", this.name)
				.append("didplayOrder", this.displayOrder)
				.toString();
	}
	
	
	

	
	
}
